<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    button{
      position: fixed;
      bottom: 100px;
      right: 100px;
    }
  </style>
</head>
<body style="height: 3000px;">
  <div id="app">
    <button v-backtop="200">按钮</button>
  </div>
  <script src="./vue.js"></script>
  <script>
    Vue.directive('backtop', {
      inserted(el, binding){
        el.style.display = "none";
        window.onscroll = () => {
          // 获取滚动举例
          const sTop = document.documentElement.scrollTop || document.body.scrollTop;
          if (sTop > binding.value) {
            // 显示
            el.style.display = "block";
          } else {
            el.style.display = "none";
          }
        }
        el.onclick = () => {
          window.scrollTo(0,0);
        }
      },
      unbind(){
        window.onscroll = null;
      }
    })
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>
</html>